import BigNumber from "@/node_modules/bignumber.js/bignumber.js";
var Web33 = require('web3');
export default {
	convertStringToHex:(value)=>{
		return new BigNumber(`${value}`).toString(16);
	},
	sanitizeHex:(hex)=> {
		hex = hex.substring(0, 2) === "0x" ? hex.substring(2) : hex;
		if (hex === "") {
			return "";
		}
		hex = hex.length % 2 !== 0 ? "0" + hex : hex;
		return "0x" + hex;
	},
	convertAmountToRawNumber:(value, decimals = 18)=>{
		return new BigNumber(`${value}`).times(new BigNumber("10").pow(decimals)).toString();
	},
	lcb(addr,caddr,abi){
		let that = this;
		return
		try{
			if (typeof web3 !== 'undefined') {
				alert(Web33)
			    web3 = new Web33(web3.currentProvider);
			} else {
			    // web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
			    web3 = new Web33(new Web3.providers.HttpProvider("https://mainnet.infura.io/yourAddress"));
			}
			alert(1)
			// 定义合约abi
			var contractAbi = abi;
			 // alert(abi)
			// 合约地址
			var contractAddress = caddr;
			 
			// 账号
			var currentAccount = addr;
			
			// 定义合约
			// var myContract = new web3.eth.Contract(contractAbi, contractAddress, {
			//     from: currentAccount, // default from address
			//     gasPrice: '10000000000' // default gas price in wei, 10 gwei in this case
			// });
			// // 查询以太币余额
			// web3.eth.getBalance(currentAccount).then(a=>{
			// 	alert("aaa"+JSON.stringify(a));
			// });
			 
			// // 查看某个账号的代币余额
			// myContract.methods.balanceOf(contractAddress).call({from: currentAccount}, function(error, result){
			//     if(!error) {
			//         console.log(result);
			//     } else {
			//         console.log(error);
			//     }
			// });
			
			
			
		}catch(e){
			//TODO handle the exception
			alert(e.message)
		}
		
	},
}